// 2025/9/16
// 两数之和2-输入有序数组

class Solution {
public:
    vector<int> twoSum(vector<int>& numbers, int target) {
        int n = numbers.size();
        for(int i = 0; i < n; i++)
        {
            int tmp = target - numbers[i];
            if(tmp < numbers[i] || tmp > numbers[n - 1])
                continue;
            int left = i + 1, right = n - 1, mid = 0;
            while(left <= right)
            {
                mid = (left + right) >> 1;
                if(numbers[mid] < tmp)
                    left = mid + 1;
                else if(numbers[mid] > tmp)
                    right = mid - 1;
                else
                    break;
            }
            if(numbers[mid] == tmp)
                return (vector<int>){i + 1, mid + 1};
        }
        return vector<int>();
    }
};